﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebshopPizzaRio
{
    public class Ingredient : System.IFormattable
    {
        private int _ingredientnr;
        private String _naam;
        private Decimal _prijs;
        private String _hoeveelheid;
        private int _aantal = 1;
        
        public Ingredient()
        {

        }

        public Ingredient(int ingredientnr, String naam, Decimal prijs, String hoeveelheid)
        {
            _ingredientnr = ingredientnr;
            _naam = naam;
            _prijs = prijs;
            _hoeveelheid = hoeveelheid;
        }

        public int Ingredientnr
        {
            get { return _ingredientnr; }
            set { _ingredientnr = value; }
        }

        public String Ingredientnaam
        {
            get { return _naam; }
            set { _naam = value; }
        }

        public Decimal ingredientprijs
        {
            get { return _prijs; }
            set { _prijs = value; }
        }

        public String hoeveelheid
        {
            get { return _hoeveelheid; }
            set { _hoeveelheid = value; }
        }

        public Decimal Totaal
        {
            get { return _prijs * _aantal; }
        }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            if (Object.ReferenceEquals(this, obj)) return true;
            if (this.GetType() != obj.GetType()) return false;

            Ingredient objItem = (Ingredient)obj;
            if (_ingredientnr == objItem.Ingredientnr) return true;

            return false;
        }

        public override int GetHashCode()
        {
            return _naam.GetHashCode();
        }

        string System.IFormattable.ToString(string format, IFormatProvider formatProvider)
        {
            if (format == null) format = "G";

            if (formatProvider != null)
            {
                ICustomFormatter formatter = formatProvider.GetFormat(this.GetType()) as ICustomFormatter;

                if (formatter != null)
                    return formatter.Format(format, this, formatProvider);
            }

            switch (format)
            {
                case "f": return String.Format("{0}{1,10}{2,10}{3,20}",
               _naam, _aantal.ToString(), _prijs.ToString("c"),
               Totaal.ToString("c"));
                case "G":
                default: return string.Format("{0}", _naam.ToString());
            }

        }
    }
}